package com.danger.Activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import java.util.HashMap;

import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import cn.smssdk.gui.RegisterPage;

public class IndexActivity extends AppCompatActivity implements View.OnClickListener {

    private Button gallery_button;
    private Button choose_image_button;
    private Button send_checkcode_button;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SMSSDK.initSDK(this, "1369975f62122", "71dfb423e1d016675c61d1b751d4d56c");
        setContentView(R.layout.activity_index);

        initView();
        initEvent();
    }

    private void initView() {
        gallery_button = (Button) findViewById(R.id.gallery_button);
        choose_image_button = (Button) findViewById(R.id.choose_image_button);
        send_checkcode_button = (Button) findViewById(R.id.send_checkcode_button);

    }

    private void initEvent() {
        gallery_button.setOnClickListener(this);
        choose_image_button.setOnClickListener(this);
        send_checkcode_button.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.gallery_button:
                intent.setClass(IndexActivity.this, GalleryFlowActivity.class);
                startActivity(intent);
                break;
            case R.id.choose_image_button:
                intent.setClass(IndexActivity.this, MainActivity.class);
                startActivity(intent);
                break;
            case R.id.send_checkcode_button:
                //打开注册页面
                RegisterPage registerPage = new RegisterPage();
                registerPage.setRegisterCallback(new EventHandler() {
                    public void afterEvent(int event, int result, Object data) {
                        // 解析注册结果
                        if (result == SMSSDK.RESULT_COMPLETE) {
                            @SuppressWarnings("unchecked")
                            HashMap<String, Object> phoneMap = (HashMap<String, Object>) data;
                            String country = (String) phoneMap.get("country");
                            String phone = (String) phoneMap.get("phone");

                            Toast.makeText(IndexActivity.this, "验证成功", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
                registerPage.show(this);
                break;
            default:
                break;
        }
    }
}
